package n1882;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	
	static int c[]=new int[1001];
	
	static boolean f[]=new boolean[1001];
	
	static int ar[] =new int[10];
	
	static int result[]=new int[10];
	
	static int S,N,rlen,clen,rcount;
	
	static void solve()
	{
		Arrays.fill(c, 0);
		Arrays.fill(f, false);
		f[0]=true;
		for(int i=0;i<clen;i++)
		{
			for(int j=ar[i];j<=S*ar[i];j++)
			{
				if(f[j-ar[i]]&&c[j-ar[i]]<S)
				{
					f[j]=true;
					if(c[j]==0||c[j]>c[j-ar[i]]+1)c[j]=c[j-ar[i]]+1;
				}
			}
		}
		int count=0;
		for(int i=1;i<f.length;i++)
		{
			if(f[i])count++;
			else break;
		}
		
		boolean subst=false;
		if(rcount==0&&rlen==0)
		{
			subst=true;//结果还没生成时，用第一行替换结果
		}
		else if(count>rcount)
		{
			subst=true;
		}else if(count==rcount)
		{
			if(clen<rlen)
			{
				subst=true;
			}else if(clen==rlen)
			{
				if(ar[clen-1]<result[clen-1])
				{
					subst=true;
				}
			}
		}
		if(subst){
			rlen=clen;
			rcount=count;
			System.arraycopy(ar, 0, result, 0, clen);
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		String line=null;
		while((line=bf.readLine())!=null)
		{
			S=Integer.parseInt(line);
			if(S==0)break;
			line=bf.readLine();
			N=Integer.parseInt(line);
			rlen=0;
			rcount=0;
			for(int i=0;i<N;i++)
			{
				line=bf.readLine();
				StringTokenizer st=new StringTokenizer(line);
				clen=Integer.parseInt(st.nextToken());
				for(int j=0;j<clen;j++)
				{
					ar[j]=Integer.parseInt(st.nextToken());
				}
				solve();
			}
			System.out.print("max coverage = "+rcount+" :");
			for(int i=0;i<rlen;i++)System.out.print(" "+result[i]);
			System.out.println();
		}
	}

}
